
from RootPath import RootPath
import yaml
from common.DBRequest import *
import os
path = os.path.join(RootPath.getRootPath(), "Application.yml")

#执行sql
def exc_sql(sql,MySQLconf):
    host = MySQLconf.get("host")
    uname = MySQLconf.get("username")
    pwd = MySQLconf.get("password")
    dbName = MySQLconf.get("db1")
    port = MySQLconf.get("port")
    list=[host,uname,pwd,dbName,port]
    result = db_query(list,sql)
    print("mysql exceute success-- 1 -- !")
    return result
#执行sql
def exc_sql2(sql,MySQLconf):
    host = MySQLconf.get("host")
    uname = MySQLconf.get("username")
    pwd = MySQLconf.get("password")
    dbName = MySQLconf.get("db2")
    port = MySQLconf.get("port")
    list=[host,uname,pwd,dbName,port]
    result = db_query(list,sql)
    print("mysql exceute success-- 1 -- !")
    return result

#查询并返回测点list
def query_device_point(deviceID,dbName):
    querySQL="select point_name as TAG_NAME from device_service where id_device="+deviceID
    ponit_info=exc_sql(querySQL,dbName)
    point_list=[]
    for index in range(len(ponit_info)):
        point_list.append(ponit_info[index].get("TAG_NAME"))
    return point_list

#测试类
# if __name__ == '__main__':
#     deivceID="10000"
#     point=query_device_point(deivceID,"db2")
#     sql = sqlContact(deivceID,point)
#     exc_sql(sql,"db1")

    # selectsql="select * from service_values_20201023 where id_device='20201022'"
    # info=exc_sql(selectsql,"db1")
    # print(info)



